package com.xoa.controller.fixAssets;

import com.xoa.dao.sms.SmsMapper;
import com.xoa.model.fixAssets.*;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.FlowFast;
import com.xoa.service.fixAssets.EduFixAssetsService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by gsb on 2017/9/5.
 */
@Controller
@RequestMapping("/eduFixAssets")
public class FixAssetsController {
    @Resource
    private EduFixAssetsService eduFixAssetsService;
    @Resource
    private SmsMapper smsMapper;


    @RequestMapping("/index")
    public String index(){
        return "/app/FixAssets/eduFixAssets/index";
    }

    @RequestMapping("/fixAssetsStatic")
    public String fixAssetsStatic(){
        return "/app/FixAssets/eduFixAssets/fixAssetsStatic";
    }

    /**
     * 固定资产管理
     * @return
     */
    @RequestMapping("/fixAssetsManager")
    public String fixAssetsManager(){
        return "/app/FixAssets/eduFixAssets/fixAssetsManager";
    }

    /**
     * 固定资产导入
     * @return
     */
    @RequestMapping("/fixAssetsInput")
    public String fixAssetsInput() { return "/app/FixAssets/eduFixAssets/fixAssetsInput"; }


    /**
     * 固定资产二维码打印页面
     * @return
     */
    @RequestMapping("/fixAssetsCodePrint")
    public String fixAssetsCodePrint() { return "/app/FixAssets/eduFixAssets/fixAssetsCodePrint"; }


    /**
     * 固定资产详情及维修,交接人详情
     * @return
     */
    @RequestMapping("/fixAssetsDetail")
    public String fixAssetsDetail() { return "/app/FixAssets/eduFixAssets/fixAssetsDetail"; }


    /**
     * 固定资产H5界面
     * @return
     */
    @RequestMapping("/fixAssetsDetailH5")
    public String fixAssetsDetailH5() { return "/app/FixAssets/eduFixAssets/fixAssetsDetailH5"; }
    /**
     * 固定资产编辑（editFlag=0 新建  editFlag=1 编辑）
     * @param editFlag
     * @param map
     * @return
     */
    @RequestMapping("/fixAssetsEdit")
    public String fixAssetsEdit(int editFlag,String id, Map<String,Object> map,HttpServletRequest request){
        map.put("editFlag",editFlag);
        map.put("id",id);
        return "/app/FixAssets/eduFixAssets/fixAssetsEdit";
    }

    /**
     * 固定资产查询
     * @return
     */
    @RequestMapping("/fixAssetsQuery")
    public String fixAssetsQuery(){
        return "/app/FixAssets/eduFixAssets/fixAssetsQuery";
    }

    /**
     * 固定资产设置
     * @return
     */
    @RequestMapping("/fixAssetsSetting")
    public String fixAssetsSetting(){
        return "/app/FixAssets/eduFixAssets/fixAssetsSetting";
    }

    /**
     * 固定资产申请
     */
    @RequestMapping("/fixAssetsApply")
    public String fixAssetsApply(){
        return "/app/FixAssets/cpEduFixAssets/fixAssetsApply";
    }

    /**
     * 资产详情
     */
    @RequestMapping("/cpfixAssetsDetail")
    public String cpFixAssetsDetail(){
        return "/app/FixAssets/cpEduFixAssets/cpFixAssetsDetail";
    }
    /**
     * 资产审批
     */
    @RequestMapping("/cpfixAssetsApprove")
        public String cpfixAssetsApprove(){
        return "/app/FixAssets/cpEduFixAssets/cpfixAssetsApprove";
    }
    /**
     * 资产盘点
     */
    @RequestMapping("/cpfixAssetsInventory")
    public String cpfixAssetsInventory(){return "/app/FixAssets/cpEduFixAssets/cpfixAssetsInventory";}
    /**
     * 资产盘点清单
     */
    @RequestMapping("/cpfixAssetsInventoryList")
    public String cpfixAssetsInventoryList(String inventoryId,HttpServletRequest request){
        //String inventoryIds="99";
        request.setAttribute("inventoryId",inventoryId);
        return "/app/FixAssets/cpEduFixAssets/cpfixAssetsInventoryList";}
    /**
     * 资产清单
     */
    @RequestMapping("/cpfixAssetsList")
    public String cpfixAssetsList(){return "/app/FixAssets/cpEduFixAssets/cpfixAssetsList";}
    /**
     * 资产汇总
     */
    @RequestMapping("/cpfixAssetsCollection")
    public String cpfixAssetsCollection(){return "/app/FixAssets/cpEduFixAssets/cpfixAssetsCollection";}

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:38:00
     * 方法介绍:   根据条件查询固定资产（所有添加满足）
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/selFixAssetsByCond")
    public ToJson<EduFixAssets> selFixAssetsByCond(@RequestParam(value="condition", required = false,defaultValue = "2")int condition,
                                                   @RequestParam(value="output", required = false,defaultValue = "0") int output,
                                                   EduFixAssets eduFixAssets, HttpServletRequest request, HttpServletResponse response, HttpSession session, Integer page, Integer pageSize, boolean useFlag){
        return eduFixAssetsService.selFixAssetsByCond(condition,output,eduFixAssets,request,response,session,page,pageSize,useFlag);
    }

    /**
     * 查找固定资产类型
     * @return
     */
    @ResponseBody
    @RequestMapping("/getFixAssetstypeName")
    public ToJson<EduFixAssetsType> getFixAssetstypeName(){
        return eduFixAssetsService.getFixAssetstypeName();
    }


    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:48:00
     * 方法介绍:   添加固定资产信息
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/insertFixAssets")
    public ToJson<EduFixAssets> insertFixAssets(HttpServletRequest request, MultipartFile imageFile, MultipartFile QRcodeFile, EduFixAssets eduFixAssets){
        return eduFixAssetsService.insertFixAssets(request,imageFile,QRcodeFile,eduFixAssets);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:48:00
     * 方法介绍:   修改固定资产信息
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/updateFixAssetsById")
    public ToJson<EduFixAssets> updateFixAssetsById(HttpServletRequest request, MultipartFile imageFile,MultipartFile QRcodeFile,EduFixAssets eduFixAssets){
        return eduFixAssetsService.updateFixAssetsById(request,imageFile,QRcodeFile,eduFixAssets);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午17:32:00
     * 方法介绍:   根据id删除固定资产信息
     * 参数说明:   @param id
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/deleteFixAssetsById")
    public ToJson<EduFixAssets> deleteFixAssetsById(String id){
        return  eduFixAssetsService.deleteFixAssetsById(id);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午10:02:00
     * 方法介绍:   固定资产导入
     * 参数说明:   @param fixAssetsName 资产名称
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/inputFixAsserts")
    public  ToJson<EduFixAssets> inputFixAsserts(HttpServletRequest request, HttpServletResponse response, MultipartFile file,HttpSession session){
        return eduFixAssetsService.inputFixAsserts(request,response,file,session);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午14:18:00
     * 方法介绍:   根据id进行查询固定资产
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/selFixAssetsById")
    ToJson<Object> selFixAssetsById(HttpServletRequest request,String id){
        return eduFixAssetsService.selFixAssetsById(request,id);
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午14:18:00
     * 方法介绍:   添加时获取id
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/getFixAssetsId")
    ToJson<EduFixAssets> getFixAssetsId(){
        return eduFixAssetsService.getFixAssetsId();
    }


    /**
     * 创建作者:   陈玲
     * 创建日期:   2018年7月20日
     * 方法介绍:   查询固定资产id企业id及二维码
     * 参数说明:
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/selFixAssetsAll")
    ToJson<EduFixAssets> selFixAssetsAll(EduFixAssets eduFixAssets){
        return eduFixAssetsService.getFixAssetsAll(eduFixAssets);
    }


    @ResponseBody
    @RequestMapping(value = "/addGoToFixAssets", produces = "application/json; charset=utf-8")
    public ToJson<FlowFast> addGoToFixAssets(String userId, String recordTime, String type , HttpServletRequest request){
        return eduFixAssetsService.addGoToFixAssets(userId,recordTime,type,request);
    }

    @RequestMapping("/selectEduFixAssets")
    @ResponseBody
    public ToJson<EduFixAssets> selectEduFixAssets(HttpServletRequest request,String assetsName,Integer isAssets,String deptId,String currrntLocation,Integer page,Integer pageSize,Boolean useFlag,String scheduler,String assetsId){
        return eduFixAssetsService.selectEduFixAssets(request,assetsName,isAssets,deptId,currrntLocation,page,pageSize,useFlag,scheduler,assetsId);
    }

    @RequestMapping("/eduFixAssetsStatistical")
    @ResponseBody
    public ToJson<List<Map<String,Object>>> eduFixAssetsStatistical(String projectId,String currrntLocation){
        return eduFixAssetsService.eduFixAssetsStatistical(projectId,currrntLocation);
    }

    @RequestMapping("/getCurrrntLocation")
    @ResponseBody
    public ToJson getCurrrntLocation(){
        return eduFixAssetsService.getCurrrntLocation();
    }

    @RequestMapping("/updateEduFixAssets")
    @ResponseBody
    public ToJson updateEduFixAssets(String id,Integer typeId,String deptId,String currutLocation,String status,String otherDept){
        return eduFixAssetsService.updateEduFixAssets(id, typeId, deptId, currutLocation, status, otherDept);
    }
    //更新调度员和修改内容及修改状态
    @RequestMapping("/updateEduFixAssetsModifyById")
    @ResponseBody
    public ToJson updateEduFixAssetsModifyById(String id,Integer typeId,String deptId,String currutLocation,String status,String otherDept,String scheduler){
        return eduFixAssetsService.updateEduFixAssetsModifyById(id, typeId, deptId, currutLocation, status, otherDept,scheduler);
    }

    @RequestMapping("/selEduFixAssets")
    @ResponseBody
    public ToJson selEduFixAssets(String assetsName,Integer typeId,String deptId,String currutLocation,Integer status,String otherDept){
        return eduFixAssetsService.selEduFixAssets(assetsName, typeId, deptId, currutLocation, status, otherDept);
    }

    //保管人页面
    @RequestMapping("/scheduler")
    public String scheduleList(HttpServletRequest request){
        return "/app/FixAssets/eduFixAssets/scheduler";
    }
    @ResponseBody
    @RequestMapping("/updateQueren")
    public ToJson updateQueren(HttpServletRequest request,String id,String schedulerstatus,String noAcceptReason){
        return eduFixAssetsService.updateQueren(request,id,schedulerstatus,noAcceptReason);
    }
    @ResponseBody
    @RequestMapping("/getEdufixAssets")
    public ToJson getEdufixAssets(HttpServletRequest request,String ids){
        String ids1 = request.getParameter("ids");
        return eduFixAssetsService.getEdufixAssets(request,ids);
    }
    @RequestMapping("/updateQuerenBatch")
    @ResponseBody
    //保管人多选接口
    public ToJson updateQuerenBatch(HttpServletRequest request,String ids){

        return eduFixAssetsService.updateQuerenBatch(request,ids);
    }

    /**
     * @作者: 张航宁
     * @时间: 2019/8/28
     * @说明: 资产设置保存接口
     */
    @ResponseBody
    @RequestMapping("/saveSetting")
    public ToJson saveSetting(String logoAttachmentId){
        return eduFixAssetsService.saveSetting(logoAttachmentId);
    }


    /**
     * @作者: 张航宁
     * @时间: 2019/8/28
     * @说明: 资产设置查询接口
     */
    @ResponseBody
    @RequestMapping("/getSetting")
    public ToJson getSetting(HttpServletRequest request){
        return eduFixAssetsService.getSetting(request);
    }
	
	  /**
     * 固定资产类型页面
     */
    @RequestMapping("/fixAssetsType")
    public String fixAssetsType(){
        return "/app/FixAssets/eduFixAssets/fixAssetsType";
    }


    /**
     * 添加固定资产类型
     */
    @ResponseBody
    @RequestMapping("/insertFixAssetsType")
    public ToJson<EduFixAssetsType> insertFixAssetsType(EduFixAssetsType eduFixAssetsType, HttpServletRequest request){
        
        return eduFixAssetsService.insertFixAssetsType(eduFixAssetsType,request);
    }
    /**
     * 根据id删除资产类型
     */
    @ResponseBody
    @RequestMapping("/delFixAssetsType")
    public ToJson<EduFixAssetsType> delFixAssetsType(Integer typeId){
        return eduFixAssetsService.delFixAssetsType(typeId);
    }
    /**
     * 根据id更新资产类型
     */
    @ResponseBody
    @RequestMapping("/updateFixAssetsType")
    public ToJson<EduFixAssetsType> updateFixAssetsType(EduFixAssetsType eduFixAssetsType,HttpServletRequest request){
        return eduFixAssetsService.updateFixAssetsType(eduFixAssetsType,request);
    }
    /**
     * 根据id查看资产类型
     */
    @ResponseBody
    @RequestMapping("/selFixAssetsTypeById")
    public ToJson<EduFixAssetsType> selFixAssetsTypeById(Integer typeId){
        return eduFixAssetsService.selFixAssetsTypeById(typeId);
    }

    @ResponseBody
    @RequestMapping("/updateDispatchAsserts")
    public  ToJson<EduFixAssets> updateDispatchAsserts(HttpServletRequest request, HttpServletResponse response, Integer type,String assetIds ){
        return eduFixAssetsService.updateAssetsType(type,assetIds);
    }
    @ResponseBody
    @RequestMapping("/insertAssetsApplys")
    public ToJson<CpAssetsApply> insertAssetsApplys(CpAssetsApply cpAssetsApply, HttpServletRequest request){
        return eduFixAssetsService.insertAssetsApplys(cpAssetsApply,request);
    }

    /**
     * 方法介绍:   添加时获取id
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/exportCpFixAssetsApply")
    ToJson<CpAssetsApply> getFixAssetsApplyId(){
        return eduFixAssetsService.getFixAssetsApplyId();
    }

    /**
     * 方法介绍:   资产申请界面展示/资产审批界面展示/资产条件查询界面展示
     * 参数说明:
     * @param flag 1为申请 2为审批
     *         flag2  4.最近三天 5.最近一周 6.最近一个月
     * @param status  0 为待审核 1 为已通过 2 为未通过 3 是归还 4是超期未归还 5 已验收
     * 返回值说明:
     */
    @ResponseBody
    @RequestMapping("/getFixAssetsApply")
    ToJson<CpAssetsApply> getFixAssetsApply(String flag2,String flag,String status,String applyId,Integer page, Integer limit, boolean useFlag,HttpServletRequest request){
        Integer pageSize=limit;
        useFlag=true;
        return eduFixAssetsService.getFixAssetsApply(flag2,flag,status,applyId,page,pageSize,useFlag,request);
    }
    /**
     * 根据id删除资产类型
     */
    @ResponseBody
    @RequestMapping("/delFixAssetsApply")
    public ToJson<CpAssetsApply> delFixAssetsApply(Integer applyId){
       // applyId=1;
        return eduFixAssetsService.delFixAssetsApply(applyId);
    }

    /**
     * 资产归还
     * @param applyId
     * @param status
     * @return
     */
    @ResponseBody
    @RequestMapping("/returnFixAssetsApply")
    public ToJson<CpAssetsApply> returnFixAssetsApply(Integer applyId,String status,HttpServletRequest request){

        return eduFixAssetsService.returnFixAssetsApply(applyId,status,request);
    }

    /**
     * 资产验收
     * @param applyId
     * @param status
     * @return
     */
    @ResponseBody
    @RequestMapping("/receiveFixAssetsApply")
    public ToJson<CpAssetsApply> receiveFixAssetsApply(Integer applyId,String status,HttpServletRequest request){
        return eduFixAssetsService.receiveFixAssetsApply(applyId,status,request);
    }

    /**
     * 资产审批
     * @param applyId
     * @param status
     * @return
     */
    @ResponseBody
    @RequestMapping("/approveFixAssetsApply")
    public ToJson<CpAssetsApply> approveFixAssetsApply(Integer applyId,String status,HttpServletRequest request){
        return eduFixAssetsService.approveFixAssetsApply(applyId,status,request);
    }


    /**
     * 新建资产盘点
     * @param cpAssetsInventory
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/fixAssetsInventory")
    public ToJson<CpAssetsApply> fixAssetsInventory(CpAssetsInventory cpAssetsInventory,HttpServletRequest request){
              /*cpAssetsInventory.setInventoryName("eee");
              cpAssetsInventory.setApplyUser("admin");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -360);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd mm:hh:ss");
        String format = dateFormat.format(calendar.getTime());
        try {
            Date date = dateFormat.parse(format);
            cpAssetsInventory.setStartAt(date);
            cpAssetsInventory.setEndAt(new Date());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cpAssetsInventory.setAssetsType("1");
        cpAssetsInventory.setManagers("admin");*/
        return eduFixAssetsService.fixAssetsInventory(cpAssetsInventory,request);
    }


    /**
     * 资产盘点清单接口
     * @param request
     * @param inventoryId
     * @param type
     * @return
     */
    @ResponseBody
    @RequestMapping("/fixAssetsGetInventory")
    public ToJson<CpAssetsInventory> fixAssetsGetInventory(HttpServletRequest request,String inventoryId,String type,Integer page, Integer limit, Boolean useFlag){
      //  inventoryId="20200119005";
      //  type="2";
        return eduFixAssetsService.fixAssetsGetInventory(request,inventoryId,type,page,limit,useFlag);
    }


    /**
     * 资产清单
     * @param page
     * @param limit
     * @param useFlag
     * @return
     */
    @ResponseBody
    @RequestMapping("/fixAssetsList")
    public ToJson<EduFixAssets> fixAssetsList( Integer page, Integer limit, Boolean useFlag){
        Integer pageSize=limit;
        useFlag=true;
        return eduFixAssetsService.fixAssetsList(page,pageSize,useFlag);
    }

    /**
     * 全部资产类别查询
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllFixAssetsType")
    public ToJson<EduFixAssetsType> getAllFixAssetsType(){
        return eduFixAssetsService.getAllFixAssetsType();
    }

    /**
     * 资产汇总
     * @return
     */
    @ResponseBody
    @RequestMapping("/fixAssetsSummary")
    public ToJson<EduFixAssetsType> fixAssetsSummary(Integer page, Integer limit, Boolean useFlag){
        return eduFixAssetsService.fixAssetsSummary(page,limit,useFlag);
    }



    @ResponseBody
    @RequestMapping("/select")
    public ToJson<CpAssetsApply> bzys(Integer applyId,String status){
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -30);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd mm:hh:ss");
        json.setObject(dateFormat.format(calendar.getTime()));
        return json;
    }


}
